<template>
	<div class="bg-white h-full w-full relative">
		<t-badge :count="reddot.rest_examine_num" class="absolute" style="z-index: 9999; top: 10px; left: 70px;" v-if="isButtonAuthority('请假审批')"></t-badge>
		<t-badge :count="reddot.overtime_examine_num" class="absolute" style="z-index: 9999; top: 10px; left: 159px;" v-if="isButtonAuthority('加班审批')"></t-badge>
		<t-badge :count="reddot.salary_examine_num" class="absolute" style="z-index: 9999; top: 10px; left: 248px;" v-if="isButtonAuthority('工资审批')"></t-badge>
		<t-tabs class="bg-white h-full w-full" :value="father" theme="card" @change="onChange">
			<t-tab-panel :value="son1" label="调休审批" v-if="isButtonAuthority('请假审批')">
					<t-tabs :defaultValue="'调休待审核'" v-if="son1 === father">
						<t-tab-panel :value="'调休待审核'" label="待审核">
							<div v-if="Boolean(restData.length)">
								<!-- 复选 -->
								<div v-for="(item, index) in restData" :key="index">
									<div class="flex justify-between items-center">
										<div class="flex">
											<t-checkbox class="ml-4" :value="item.rl_id" :onChange="restCheckboxChange" v-model="item.checkbox"></t-checkbox>
											<div>
												<h5 class="pt-4 pl-4 text-base text-blue-700">{{item.proposer_name}}申请调休</h5>
												<div class="flex pl-4 pt-2">
													<div class="text-gray-400 mr-2 text-right">
														<p class="pb-2">开始时间：</p>
														<p class="pb-2">结束时间：</p>
													</div>
													<div class="w-40">
														<p class="pb-2">{{item.start_date}}</p>
														<p>{{item.end_date}}</p>
													</div>
													<div class="text-gray-400 mr-2 text-right">
														<p class="pb-2">申请人：</p>
														<p>申请时间：</p>
													</div>
													<div>
														<p class="pb-2">{{item.proposer_name}}</p>
														<p>{{item.proposer_date}}</p>
													</div>
												</div>
												<p class="pl-4"><span class="text-gray-400 mr-2">调休事由：</span><span>{{item.reason}}</span></p>
											</div>
										</div >
										<div class="flex mr-4">
											<t-button theme="default" @click="refuseRest(item.rl_id)">驳回</t-button>
											<t-button class="ml-4" @click="agreeRest(item.rl_id)">同意</t-button>
										</div>
									</div>
									<t-divider></t-divider>
								</div>	
								<!-- 全选 -->
								<div class="flex justify-between items-center p-4 mt-auto">
									<t-checkbox :indeterminate="restIndeterminate" v-model="restAllCheckboxValue" :onChange="restAllCheckboxChange" label="全选"></t-checkbox>
									<div class="flex">
										<t-button theme="default" @click="refuseRestLists" :disabled="restValueArr.length === 0">驳回</t-button>
										<t-button class="ml-4" @click="agreeRestLists" :disabled="restValueArr.length === 0">批量同意</t-button>
									</div>
								</div>
							</div>
							<div v-if="!Boolean(restData.length)" class="flex justify-center">
								<div class="pt-16">
									<img src="/images/status/noReview.png" class="w-96">
									<p class="text-center pt-8">当前暂无待审核的记录</p>
								</div>
							</div>
						</t-tab-panel>
						<t-tab-panel :value="'调休已同意'" label="已同意">
							<div v-if="Boolean(restProcessedData[0].length)">
								<!-- 复选 -->
								<div v-for="(item, index) in restProcessedData[0]" :key="index">
									<div class="flex">
										<div>
											<h5 class="pt-4 pl-4 text-base text-green-500">{{item.proposer_name}}的调休申请已同意</h5>
											<div class="flex pl-4 pt-2">
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">开始时间：</p>
													<p class="pb-2">结束时间：</p>
												</div>
												<div class="w-40">
													<p class="pb-2">{{item.start_date}}</p>
													<p>{{item.end_date}}</p>
												</div>
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">申请人：</p>
													<p>申请时间：</p>
												</div>
												<div>
													<p class="pb-2">{{item.proposer_name}}</p>
													<p>{{item.proposer_date}}</p>
												</div>
											</div>
											<p class="pl-4"><span class="text-gray-400 mr-2">调休事由：</span><span>{{item.reason}}</span></p>
										</div>
									</div >
									<t-divider></t-divider>
								</div>
							</div>
							<div v-if="!Boolean(restProcessedData[0].length)" class="flex justify-center">
								<div class="pt-16">
									<img src="/images/status/noReview.png" class="w-96">
									<p class="text-center pt-8">当前暂无审核的记录</p>
								</div>
							</div>
						</t-tab-panel>
						<t-tab-panel :value="'调休已驳回'" label="已驳回">
							<div v-if="Boolean(restProcessedData[1].length)">
								<!-- 复选 -->
								<div v-for="(item, index) in restProcessedData[1]" :key="index">
									<div class="flex">
										<div>
											<h5 class="pt-4 pl-4 text-base text-red-500">{{item.proposer_name}}的调休申请被驳回</h5>
											<div class="flex pl-4 pt-2">
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">开始时间：</p>
													<p class="pb-2">结束时间：</p>
												</div>
												<div class="w-40">
													<p class="pb-2">{{item.start_date}}</p>
													<p>{{item.end_date}}</p>
												</div>
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">申请人：</p>
													<p>申请时间：</p>
												</div>
												<div>
													<p class="pb-2">{{item.proposer_name}}</p>
													<p>{{item.proposer_date}}</p>
												</div>
											</div>
											<p class="pl-4"><span class="text-gray-400 mr-2">调休事由：</span><span>{{item.reason}}</span></p>
										</div>
									</div >
									<t-divider></t-divider>
								</div>
							</div>
							<div v-if="!Boolean(restProcessedData[1].length)" class="flex justify-center">
								<div class="pt-16">
									<img src="/images/status/noReview.png" class="w-96">
									<p class="text-center pt-8">当前暂无审核的记录</p>
								</div>
							</div>
						</t-tab-panel>
					</t-tabs>
			</t-tab-panel>
			
			<t-tab-panel :value="son2" label="加班审批" v-if="isButtonAuthority('加班审批')">
				<t-tabs defaultValue="加班待审核" v-if="son2 === father">
					<t-tab-panel value="加班待审核" label="待审核">
						<div v-if="Boolean(overTimeData.length)">
							<!-- 复选 -->
							<div v-for="(item, index) in overTimeData" :key="index">
								<div class="flex justify-between items-center">
									<div class="flex">
										<t-checkbox class="ml-4" :value="item.ol_id" :onChange="overTimeCheckboxChange" v-model="item.checkbox"></t-checkbox>
										<div>
											<h5 class="pt-4 pl-4 text-base text-blue-700">{{item.proposer_name}}的加班申请</h5>
											<div class="flex pl-4 pt-2">
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">加班日期：</p>
													<p class="pb-2">加班时长：</p>
												</div>
												<div class="w-40">
													<p class="pb-2">{{item.overtime_date}}</p>
													<p>{{item.overtime_hour}}小时</p>
												</div>
												<div class="text-gray-400 mr-2 text-right">
													<p class="pb-2">申请人：</p>
													<p>申请时间：</p>
												</div>
												<div>
													<p class="pb-2">{{item.proposer_name}}</p>
													<p>{{item.proposer_date}}</p>
												</div>
											</div>
											<p class="pl-4"><span class="text-gray-400 mr-2">加班事由：</span><span>{{item.reason}}</span></p>
										</div>
									</div >
									<div class="flex mr-4">
										<t-button theme="default" @click="refuseOvertime(item.ol_id)">驳回</t-button>
										<t-button class="ml-4" @click="agreeOvertime(item.ol_id)">同意</t-button>
									</div>
								</div>
								<t-divider></t-divider>
							</div>	
							<!-- 全选 -->
							<div class="flex justify-between items-center p-4 mt-auto">
								<t-checkbox :indeterminate="overTimeIndeterminate" v-model="overTimeAllCheckboxValue" :onChange="overTimeAllCheckboxChange" label="全选"></t-checkbox>
								<div class="flex">
									<t-button theme="default" @click="refuseOvertimeLists" :disabled="overTimeValueArr.length === 0">驳回</t-button>
									<t-button class="ml-4" @click="agreeOvertimeLists" :disabled="overTimeValueArr.length === 0">批量同意</t-button>
								</div>
							</div>
						</div>
						<div v-if="!Boolean(overTimeData.length)" class="flex justify-center">
							<div class="pt-16">
								<img src="/images/status/noReview.png" class="w-96">
								<p class="text-center pt-8">当前暂无待审核的记录</p>
							</div>
						</div>
					</t-tab-panel>
					<t-tab-panel value="加班已通过" label="已通过">
						<div v-if="Boolean(overTimeProcessedData[0].length)">
							<!-- 复选 -->
							<div v-for="(item, index) in overTimeProcessedData[0]" :key="index">
								<div class="flex">
									<div>
										<h5 class="pt-4 pl-4 text-base text-green-500">{{item.proposer_name}}的加班申请已通过</h5>
										<div class="flex pl-4 pt-2">
											<div class="text-gray-400 mr-2 text-right">
												<p class="pb-2">加班日期：</p>
												<p class="pb-2">加班时长：</p>
											</div>
											<div class="w-40">
												<p class="pb-2">{{item.overtime_date}}</p>
												<p>{{item.overtime_hour}}小时</p>
											</div>
											<div class="text-gray-400 mr-2 text-right">
												<p class="pb-2">申请人：</p>
												<p>申请时间：</p>
											</div>
											<div>
												<p class="pb-2">{{item.proposer_name}}</p>
												<p>{{item.proposer_date}}</p>
											</div>
										</div>
										<p class="pl-4"><span class="text-gray-400 mr-2">加班事由：</span><span>{{item.reason}}</span></p>
									</div>
								</div >
								<t-divider></t-divider>
							</div>	
						</div>
						<div v-if="!Boolean(overTimeProcessedData[0].length)" class="flex justify-center">
							<div class="pt-16">
								<img src="/images/status/noReview.png" class="w-96">
								<p class="text-center pt-8">当前暂无审核的记录</p>
							</div>
						</div>
					</t-tab-panel>
					<t-tab-panel value="加班已驳回" label="已驳回">
						<div v-if="Boolean(overTimeProcessedData[1].length)">
							<!-- 复选 -->
							<div v-for="(item, index) in overTimeProcessedData[1]" :key="index">
								<div class="flex">
									<div>
										<h5 class="pt-4 pl-4 text-base text-red-500">{{item.proposer_name}}的加班申请被驳回</h5>
										<div class="flex pl-4 pt-2">
											<div class="text-gray-400 mr-2 text-right">
												<p class="pb-2">加班日期：</p>
												<p class="pb-2">加班时长：</p>
											</div>
											<div class="w-40">
												<p class="pb-2">{{item.overtime_date}}</p>
												<p>{{item.overtime_hour}}小时</p>
											</div>
											<div class="text-gray-400 mr-2 text-right">
												<p class="pb-2">申请人：</p>
												<p>申请时间：</p>
											</div>
											<div>
												<p class="pb-2">{{item.proposer_name}}</p>
												<p>{{item.proposer_date}}</p>
											</div>
										</div>
										<p class="pl-4"><span class="text-gray-400 mr-2">加班事由：</span><span>{{item.reason}}</span></p>
									</div>
								</div >
								<t-divider></t-divider>
							</div>	
						</div>
						<div v-if="!Boolean(overTimeProcessedData[1].length)" class="flex justify-center">
							<div class="pt-16">
								<img src="/images/status/noReview.png" class="w-96">
								<p class="text-center pt-8">当前暂无审核的记录</p>
							</div>
						</div>
					</t-tab-panel>
				</t-tabs>
			</t-tab-panel>
			
			<t-tab-panel :value="son3" label="工资审批" v-if="isButtonAuthority('工资审批')">
				<t-tabs defaultValue="工资待审核" v-if="son3 === father">
					<t-tab-panel value="工资待审核" label="待审核">
						<div class="p-4">
							<div class="w-full">
								<div class="flex float-right">
									<t-button class="mr-4" variant="outline" @click="Reset()">重置</t-button>
									<t-button class="mr-4" @click="save()" :disabled="selectedRowKeys.length === 0">保存</t-button>
									<t-button theme="success" @click="submit()" :disabled="selectedRowKeys.length === 0">发布</t-button>
								</div>
								<div class="clear-both"></div>
							</div>
							<div v-for="(item, index) in data[0]" :key="index" class="mb-8">
								<p class="text-gray-900 text-lg">{{item[0].s_date.slice(0,4)}}年{{item[0].s_date.slice(5)}}月工资表</p>
								<t-table
								:bordered="true"
								rowKey="s_id"
								:columns="columnsNo"
								:data="item"
								:selected-row-keys="selectedRowKeys"
								@select-change="rehandleSelectChange"
								:pagination="{ defaultCurrent: 1, defaultPageSize: 20, total: item.length }"
								class="mt-2"
								>
									<template #s_award="{row}">
										<t-input v-model="row.s_award"></t-input>
									</template>
									<template #s_fine="{row}">
										<t-input v-model="row.s_fine"></t-input>
									</template>
									<template #s_endowent_insurance="{row}">
										<t-input v-model="row.s_endowent_insurance"></t-input>
									</template>
									<template #s_medical_insurance="{row}">
										<t-input v-model="row.s_medical_insurance"></t-input>
									</template>
									<template #s_unemployment_insurance="{row}">
										<t-input v-model="row.s_unemployment_insurance"></t-input>
									</template>
									<template #s_employment_insurance="{row}">
										<t-input v-model="row.s_employment_insurance"></t-input>
									</template>
									<template #s_maternity_insurance="{row}">
										<t-input v-model="row.s_maternity_insurance"></t-input>
									</template>
									<template #s_remark="{row}">
										<t-input v-model="row.s_remark" placeholder="请输入备注"></t-input>
									</template>
								</t-table>
							</div>
							<div class="text-gray-400 mb-2">
								<p>工资计算公式<span class="text-red-800"> *</span></p>
								<p>实际应发 = （岗位工资 / 满勤天数 * 实际出勤天数）+ 奖金 +（岗位工资 / 满勤天数 / 8 * 加班时数）- 扣款 - 五险</p>
							</div>
						</div>
					</t-tab-panel>
					<t-tab-panel value="工资已发布" label="已发布" class="p-4">
						<div v-for="(item, index) in data[1]" :key="index" class="mb-8">
							<p class="text-gray-900 text-lg mb-4">{{item[0].s_date.slice(0,4)}}年{{item[0].s_date.slice(5)}}月工资表</p>
							<t-table
							:bordered="true"
							rowKey="s_id"
							:columns="columnsYes"
							:data="item"
							:pagination="{ defaultCurrent: 1, defaultPageSize: 20, total: item.length }"
							></t-table>
						</div>
					</t-tab-panel>
				</t-tabs>
			</t-tab-panel>
		</t-tabs>
	</div>
</template>

<script>
	import { getUserId } from '@/unit/auth'
	import loot from '@/unit/loot'
	import { isButtonAuthority } from '@/unit/buttonAuthority'
	
	const getColumsNo = (isFixedColumn) => [
		{ colKey: 'row-select', type: 'multiple', fixed: 'left', attrs:{['style']: "background-color: #f7f7f7"}},
		{ colKey: 's_user_name', title: '员工昵称', fixed: 'left', width: 120, attrs:{['style']: "background-color: #f7f7f7"}},
		{ colKey: 's_department_name', title: '所属部门', width: 120},
		{ colKey: 's_position_name', title: '岗位职称', width: 120 },
		{ colKey: 's_shoud_salary', title: '满勤天数', width: 120 },
		{ colKey: 's_office_day', title: '实际出勤天数', width: 140 },
		{ colKey: 's_rest_day', title: '调休', width: 80 },
		{ colKey: 's_overtime_day', title: '加班', width: 80 },
		{ colKey: 's_post_salary', title: '岗位工资', width: 120 },
		{ colKey: 's_award', title: '绩效奖励', width: 120 },
		{ colKey: 's_fine', title: '扣款', width: 120 },
		{ colKey: 's_endowent_insurance', title: '养老保险', width: 120 },
		{ colKey: 's_medical_insurance', title: '医疗保险', width: 120 },
		{ colKey: 's_unemployment_insurance', title: '失业保险', width: 120 },
		{ colKey: 's_employment_insurance', title: '工伤保险', width: 120 },
		{ colKey: 's_maternity_insurance', title: '生育保险', width: 120 },
		{ colKey: 's_practical_salary', title: '实际应发', width: 160 },
		{ colKey: 's_remark', title: '备注', width: 200 }
	]
	
	const getColumsYes = (isFixedColumn) => [
		{ colKey: 's_user_name', title: '员工昵称', fixed: 'left', width: 120, attrs:{['style']: "background-color: #f7f7f7"}},
		{ colKey: 's_department_name', title: '所属部门', width: 120},
		{ colKey: 's_position_name', title: '岗位职称', width: 120 },
		{ colKey: 's_shoud_salary', title: '满勤天数', width: 120 },
		{ colKey: 's_office_day', title: '实际出勤天数', width: 140 },
		{ colKey: 's_rest_day', title: '调休', width: 80 },
		{ colKey: 's_overtime_day', title: '加班', width: 80 },
		{ colKey: 's_post_salary', title: '岗位工资', width: 120 },
		{ colKey: 's_award', title: '绩效奖励', width: 120 },
		{ colKey: 's_fine', title: '扣款', width: 120 },
		{ colKey: 's_endowent_insurance', title: '养老保险', width: 120 },
		{ colKey: 's_medical_insurance', title: '医疗保险', width: 120 },
		{ colKey: 's_unemployment_insurance', title: '失业保险', width: 120 },
		{ colKey: 's_employment_insurance', title: '工伤保险', width: 120 },
		{ colKey: 's_maternity_insurance', title: '生育保险', width: 120 },
		{ colKey: 's_practical_salary', title: '实际应发', width: 160 },
		{ colKey: 's_remark', title: '备注', width: 200 }
	]
	
	export default {
		name: 'MyApprove',
		inject: ['reload'],
		data(){
			return {
				// tab
				father: 1,
				son1: 1,
				son2: 2,
				son3: 3,
				// 调休申请
				restData: [],
				restIndeterminate: false,
				restAllCheckboxValue: false,
				restValueArr: [],
				restProcessedData: [[], []],
				// 加班申请
				overTimeData: [],
				overTimeIndeterminate: false,
				overTimeAllCheckboxValue: false,
				overTimeValueArr: [],
				overTimeProcessedData: [[], []],
				// 工资审核
				data: [[],[]],
				fixedColumn: false,
				selectedRowKeys: [],
				mydialog: null,
				visible: false,
				loading: {},
				cascaderValue: []
			}
		},
		computed: {
			// 未提交表头配置
			columnsNo(){
				return getColumsNo(this.fixedColumn)
			},
			// 已提交表头配置
			columnsYes(){
				return getColumsYes(this.fixedColumn)
			},
			// 徽标信息
			reddot(){
				return this.$store.state.user.reddot
			},
		},
		watch: {
			// 监听data，自动计算实际工资
			data: {
				deep:true,
				handler(){
					clearTimeout(this.timeout);
					this.timeout = setTimeout(() => {
						for(let i = 0; i < this.data[0].length ; i++){
							this.data[0][i].map(item => {
								for(let i in item){
									if( item[i] === '' && Object.keys(item) !== 's_remark' ){ item[i] = 0 }
								}
								item.s_practical_salary = loot.keepTwoDecimal((item.s_post_salary / item.s_shoud_salary * item.s_office_day) + parseInt(item.s_award) + (item.s_post_salary / item.s_shoud_salary / 8 * item.s_overtime_day) - item.s_fine - item.s_endowent_insurance - item.s_medical_insurance - item.s_unemployment_insurance - item.s_maternity_insurance - item.s_employment_insurance)
							})
						}
					}, 500);
				}
			},
		},
		methods: {
			// 权限审核
			isButtonAuthority(str){
				return isButtonAuthority(str)
			},
			// 重置
			Reset(){
				this.reload()
			},
			// 处理提交的数据
			processingData(){
				let arr = []
				let index = 0
				for(let i = 0 ; i < this.data[0].length ; i++){
					this.data[0][i].map(item => {
						for(let j = 0 ; j < this.selectedRowKeys.length ; j++){
							if(item.s_id == this.selectedRowKeys[j]){
								arr[index] = item
								index ++
							}
						}
					})
				}
				index = 0
				arr.map(item => {
					delete item.s_user_name
					delete item.s_department_name
					delete item.s_position_name
					delete item.s_shoud_salary
				})
				return arr
			},
			// 提交
			submit(){
				if (this.mydialog) {
					this.mydialog.show();
					return;
				}
				this.mydialog = this.$dialog({
					header: '提示',
					body: '是否通过，审核通过后将无法修改，对应工资条员工将可查看自己对应的工资条',
					onConfirm: ({ e }) => {
						let arr = this.processingData()
						this.$store.dispatch('salary/agreeSalary', arr).then(res => {
							if(res.status === 0){
								this.$message.success(res.message)
								this.reload()
								const query = { user_id: getUserId() }
								this.$store.dispatch('user/getReddot', query)
							} else {
								this.$message.error(res.message)
							}
						})
						this.mydialog.hide();
					},
				});
			},
			// 保存
			save(){
				let arr = this.processingData()
				this.$store.dispatch('salary/saveSalary', arr).then(res => {
					if(res.status === 0){
						this.$message.success(res.message)
						this.reload()
					} else {
						this.$message.error(res.message)
					}
				})
			},
			// 表格复选框
			rehandleSelectChange(value, { selectedRowData }){
				this.selectedRowKeys = value
			},
			// 获取表格基本信息
			getSubmitSalary(arr){
				this.$store.dispatch('salary/getSubmitSalary').then(res => {
					if (res.status === 0){
						// 计算应上班天数
						res.data.map(item => {
							item.s_shoud_salary = item.s_all_day - item.s_rest_all_day
						})
						// 对res.data进行分组
						res.data.map(item => {
							if (item.s_audit_state === 1){
								this.data[0].push(item)
							} else {
								this.data[1].push(item)
							}
						})
						// 对res.data进行二次分组，将工资月份相同的分为一组
						const groupBy = (array, f) => {
							let groups = {}
							array.forEach( o => {
								let group = JSON.stringify(f(o))
								groups[group] = groups[group] || []
								groups[group].push(o)
							})
							return Object.keys(groups).map((group) => {
								return groups[group]
							})
						}
						this.data[0] = groupBy(this.data[0], (item) => {return item.s_date})
						this.data[1] = groupBy(this.data[1], (item) => {return item.s_date})
						// 对 发布 列表进行排序
					} else {
						this.$message.error(res.message)
					}
				})
			},
			
			// 批量同意加班
			agreeOvertimeLists(){
				let arr = []
				this.overTimeValueArr.map((item, index) => {
					let body = { ol_id: item }
					this.$store.dispatch(`attendance/agreeOvertime`, body).then(res => {
						if(index === this.overTimeValueArr.length - 1){
							this.$message.success('操作成功，所选择申请已通过')
							let query = {
								user_id: getUserId()
							}
							this.getAuditOvertimeLog(query)
							this.$store.dispatch('user/getReddot', query)
						}
					})
				})
			},
			// 批量驳回加班
			refuseOvertimeLists(){
				let arr = []
				this.overTimeValueArr.map((item, index) => {
					let body = { ol_id: item }
					this.$store.dispatch(`attendance/refuseOvertime`, body).then(res => {
						if(index === this.overTimeValueArr.length - 1){
							this.$message.success('操作成功，所选择申请已被驳回')
							let query = {
								user_id: getUserId()
							}
							this.getAuditOvertimeLog(query)
							this.$store.dispatch('user/getReddot', query)
						}
					})
				})
			},
			// 驳回加班
			refuseOvertime(id){
				let body = {}
				body.ol_id = id
				this.$store.dispatch(`attendance/refuseOvertime`, body).then( res => {
					res.status === 0 ? this.$message.success('操作成功，该申请已被驳回') : this.$message.error(res.message)
					let query = {
						user_id: getUserId()
					}
					this.getAuditOvertimeLog(query)
					this.$store.dispatch('user/getReddot', query)
				})
			},
			// 同意加班
			agreeOvertime(id){
				let body = {}
				body.ol_id = id
				this.$store.dispatch(`attendance/agreeOvertime`, body).then( res => {
					res.status === 0 ? this.$message.success('操作成功，该申请已同意') : this.$message.error(res.message)
					let query = {
						user_id: getUserId()
					}
					this.getAuditOvertimeLog(query)
					this.$store.dispatch('user/getReddot', query)
				})
			},
			// 获取加班申请记录
			getAuditOvertimeLog(query){
				this.$store.dispatch('attendance/getAuditOvertimeLog', query).then(res => {
					if(res.status == 0){
						this.overTimeData = []
						this.overTimeProcessedData = [[],[]]
						res.data.map(item => {
							if(item.proposer_state == 0){
								this.overTimeData.push(item) // 存入未审核数据
							} else if(item.proposer_state == 1){
								this.overTimeProcessedData[0].push(item) // 存入审核已通过
							} else {
								this.overTimeProcessedData[1].push(item) // 存入审核未通过
							}
						})
						this.overTimeData.forEach(item => {
							item.checkbox = false
						})
					}
				})
			},
			// 加班全选框改变
			overTimeAllCheckboxChange(value){
				if(value){
					this.overTimeAllCheckboxValue = value
					this.overTimeIndeterminate = false
					this.overTimeValueArr = []
					for(let i = 0 ; i < this.overTimeData.length ; i++){
						this.overTimeData[i].checkbox = true
						this.overTimeValueArr.push(this.overTimeData[i].ol_id)
					}
				} else {
					this.overTimeAllCheckboxValue = value
					this.overTimeIndeterminate = false
					this.overTimeValueArr = []
					for(let i = 0 ; i < this.overTimeData.length ; i++){
						this.overTimeData[i].checkbox = false
					}
				}
			},
			// 加班复选框改变
			overTimeCheckboxChange(value, e){
				if(value){
					this.overTimeValueArr.push(e.e.path[0]._value)
					this.overTimeAllCheckboxValue = this.overTimeValueArr.length === this.overTimeData.length
					if(this.overTimeAllCheckboxValue){
						this.overTimeIndeterminate = false
					} else {
						this.overTimeIndeterminate = true
					}
				} else {
					for(let i = 0 ; i < this.overTimeValueArr.length ; i++){
						if(this.overTimeValueArr[i] === e.e.path[0]._value){
							this.overTimeValueArr.splice(i, 1)
						}
					}
					this.overTimeAllCheckboxValue = this.overTimeValueArr.length === this.overTimeData.length
					if(this.overTimeValueArr.length > 0){ this.overTimeIndeterminate = true } else { this.overTimeIndeterminate = false }
				}
			},
			
			// 批量驳回
			refuseRestLists(){
				let arr = []
				this.restValueArr.map((item, index) => {
					let body = { rl_id: item }
					this.$store.dispatch(`attendance/refuseRest`, body).then(res => {
						if(index === this.restValueArr.length - 1){
							this.$message.success('操作成功，所选择申请已被驳回')
							let query = {
								user_id: getUserId()
							}
							this.getAuditRsetLog(query)
							this.$store.dispatch('user/getReddot', query)
						}
					})
				})
			},
			// 批量同意
			agreeRestLists(){
				let arr = []
				this.restValueArr.map((item, index) => {
					let body = { rl_id: item }
					this.$store.dispatch(`attendance/agreeRest`, body).then(res => {
						if(index === this.restValueArr.length - 1){
							this.$message.success('操作成功，所选择申请已通过')
							let query = {
								user_id: getUserId()
							}
							this.getAuditRsetLog(query)
							this.$store.dispatch('user/getReddot', query)
						}
					})
				})
			},
			// 驳回调休（单个）
			refuseRest(id){
				let body = {}
				body.rl_id = id
				this.$store.dispatch(`attendance/refuseRest`, body).then( res => {
					res.status === 0 ? this.$message.success('操作成功，该申请已驳回') : this.$message.error(res.message)
					let query = {
						user_id: getUserId()
					}
					this.getAuditRsetLog(query)
					this.$store.dispatch('user/getReddot', query)
				})
			},
			// 同意调休（单个）
			agreeRest(id){
				let body = {}
				body.rl_id = id
				this.$store.dispatch(`attendance/agreeRest`, body).then( res => {
					res.status === 0 ? this.$message.success('操作成功，该申请已同意') : this.$message.error(res.message)
					let query = {
						user_id: getUserId()
					}
					this.getAuditRsetLog(query)
					this.$store.dispatch('user/getReddot', query)
				})
			},
			// 查询调休申请
			getAuditRsetLog(query){
				this.$store.dispatch('attendance/getAuditRsetLog', query).then(res => {
					if(res.status == 0){
						this.restData = []
						this.restProcessedData = [[],[]]
						res.data.map(item => {
							if(item.proposer_state == 0){
								this.restData.push(item) // 存入未审核数据
							} else if(item.proposer_state == 1){
								this.restProcessedData[0].push(item) // 存入审核已通过
							} else {
								this.restProcessedData[1].push(item) // 存入审核未通过
							}
						})
						this.restData.forEach(item => {
							item.checkbox = false
						})
					}
				})
			},
			// 调休申请全选框改变
			restAllCheckboxChange(value){
				if(value){
					this.restAllCheckboxValue = value
					this.restIndeterminate = false
					this.restValueArr = []
					for(let i = 0 ; i < this.restData.length ; i++){
						this.restData[i].checkbox = true
						this.restValueArr.push(this.restData[i].rl_id)
					}
				} else {
					this.restAllCheckboxValue = value
					this.restIndeterminate = false
					this.restValueArr = []
					for(let i = 0 ; i < this.restData.length ; i++){
						this.restData[i].checkbox = false
					}
				}
			},
			// 调休申请复选框改变
			restCheckboxChange(value, e){
				if(value){
					this.restValueArr.push(e.e.path[0]._value)
					this.restAllCheckboxValue = this.restValueArr.length === this.restData.length
					if(this.restAllCheckboxValue){
						this.restIndeterminate = false
					} else {
						this.restIndeterminate = true
					}
				} else {
					for(let i = 0 ; i < this.restValueArr.length ; i++){
						if(this.restValueArr[i] === e.e.path[0]._value){
							this.restValueArr.splice(i, 1)
						}
					}
					this.restAllCheckboxValue = this.restValueArr.length === this.restData.length
					if(this.restValueArr.length > 0){ this.restIndeterminate = true } else { this.restIndeterminate = false }
				}
			},
			
			// tab组件切换
			onChange(value){
				this.father = value
			}
		},
		created() {
			let query = {
				user_id: getUserId()
			}
			this.getAuditRsetLog(query)
			this.getAuditOvertimeLog(query)
			this.$store.dispatch('salary/getUserList')
			// 判断用户权限，根据权限的情况默认展示对应的选项
			if(isButtonAuthority('请假审批')){
				this.father = 1
			} else {
				if(isButtonAuthority('加班审批')){
					this.father = 2
				} else {
					this.father = 3
				}
			}
		},
		mounted(){
			this.getSubmitSalary()
		}
	}
</script>